<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.14"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>FabGL: Others/MouseStudio/MouseStudio.ino</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  $(document).ready(initResizable);
/* @license-end */</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="doxygen-awesome.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">FabGL
   </div>
   <div id="projectbrief">ESP32 Display Controller and Graphics Library</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.14 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('_others_2_mouse_studio_2_mouse_studio_8ino-example.html','');});
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">Others/MouseStudio/MouseStudio.ino</div>  </div>
</div><!--header-->
<div class="contents">
<p>PS/2 mouse events</p>
<div class="fragment"><div class="line"><span class="comment">/*</span></div><div class="line"><span class="comment">  Created by Fabrizio Di Vittorio (fdivitto2013@gmail.com) - &lt;http://www.fabgl.com&gt;</span></div><div class="line"><span class="comment">  Copyright (c) 2019-2021 Fabrizio Di Vittorio.</span></div><div class="line"><span class="comment">  All rights reserved.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">* Please contact fdivitto2013@gmail.com if you need a commercial license.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">* This library and related software is available under GPL v3.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">  FabGL is free software: you can redistribute it and/or modify</span></div><div class="line"><span class="comment">  it under the terms of the GNU General Public License as published by</span></div><div class="line"><span class="comment">  the Free Software Foundation, either version 3 of the License, or</span></div><div class="line"><span class="comment">  (at your option) any later version.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">  FabGL is distributed in the hope that it will be useful,</span></div><div class="line"><span class="comment">  but WITHOUT ANY WARRANTY; without even the implied warranty of</span></div><div class="line"><span class="comment">  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span></div><div class="line"><span class="comment">  GNU General Public License for more details.</span></div><div class="line"><span class="comment"></span></div><div class="line"><span class="comment">  You should have received a copy of the GNU General Public License</span></div><div class="line"><span class="comment">  along with FabGL.  If not, see &lt;http://www.gnu.org/licenses/&gt;.</span></div><div class="line"><span class="comment"> */</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="fabgl_8h.html">fabgl.h</a>&quot;</span></div><div class="line"></div><div class="line"></div><div class="line"><a name="_a0"></a><a class="code" href="classfabgl_1_1_p_s2_controller.html">fabgl::PS2Controller</a> PS2Controller;</div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">void</span> printHelp()</div><div class="line">{</div><div class="line">  Serial.printf(<span class="stringliteral">&quot;\n\nPS/2 Mouse Studio\n&quot;</span>);</div><div class="line">  Serial.printf(<span class="stringliteral">&quot;Chip Revision: %d   Chip Frequency: %d MHz\n&quot;</span>, ESP.getChipRevision(), ESP.getCpuFreqMHz());</div><div class="line"></div><div class="line">  printInfo();</div><div class="line"></div><div class="line">  Serial.printf(<span class="stringliteral">&quot;Commands:\n&quot;</span>);</div><div class="line">  Serial.printf(<span class="stringliteral">&quot;  r = Reset  s = Change Sample Rate  e = Change Resolution  c = Change Scaling\n&quot;</span>);</div><div class="line">  Serial.printf(<span class="stringliteral">&quot;Various:\n&quot;</span>);</div><div class="line">  Serial.printf(<span class="stringliteral">&quot;  h = Print This help\n\n&quot;</span>);</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">void</span> printInfo()</div><div class="line">{</div><div class="line">  <span class="keyword">auto</span> mouse = PS2Controller.<a name="a1"></a><a class="code" href="classfabgl_1_1_p_s2_controller_ae2166f0cfb03c3ff63144ecd7b602bec.html#ae2166f0cfb03c3ff63144ecd7b602bec">mouse</a>();</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> (mouse-&gt;isMouseAvailable()) {</div><div class="line">    Serial.write(<span class="stringliteral">&quot;Device Id = &quot;</span>);</div><div class="line">    <span class="keywordflow">switch</span> (mouse-&gt;identify()) {</div><div class="line">      <span class="keywordflow">case</span> PS2DeviceType::OldATKeyboard:</div><div class="line">        Serial.write(<span class="stringliteral">&quot;\&quot;Old AT Keyboard\&quot;&quot;</span>);</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> PS2DeviceType::MouseStandard:</div><div class="line">        Serial.write(<span class="stringliteral">&quot;\&quot;Standard Mouse\&quot;&quot;</span>);</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> PS2DeviceType::MouseWithScrollWheel:</div><div class="line">        Serial.write(<span class="stringliteral">&quot;\&quot;Mouse with scroll wheel\&quot;&quot;</span>);</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> PS2DeviceType::Mouse5Buttons:</div><div class="line">        Serial.write(<span class="stringliteral">&quot;\&quot;5 Buttons Mouse\&quot;&quot;</span>);</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> PS2DeviceType::MF2KeyboardWithTranslation:</div><div class="line">        Serial.write(<span class="stringliteral">&quot;\&quot;MF2 Keyboard with translation\&quot;&quot;</span>);</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> PS2DeviceType::M2Keyboard:</div><div class="line">        Serial.write(<span class="stringliteral">&quot;\&quot;MF2 keyboard\&quot;&quot;</span>);</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">default</span>:</div><div class="line">        Serial.write(<span class="stringliteral">&quot;\&quot;Unknown\&quot;&quot;</span>);</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">    }</div><div class="line">  } <span class="keywordflow">else</span></div><div class="line">    Serial.write(<span class="stringliteral">&quot;Mouse Error!&quot;</span>);</div><div class="line">  Serial.write(<span class="stringliteral">&quot;\n&quot;</span>);</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">void</span> setup()</div><div class="line">{</div><div class="line">  Serial.<a name="a2"></a><a class="code" href="classfabgl_1_1_mouse_a56921ef9b7157bb48751c7517531a798.html#a56921ef9b7157bb48751c7517531a798">begin</a>(115200);</div><div class="line">  delay(500);  <span class="comment">// avoid garbage into the UART</span></div><div class="line">  Serial.write(<span class="stringliteral">&quot;\n\nReset\n&quot;</span>);</div><div class="line"></div><div class="line">  PS2Controller.<a name="a3"></a><a class="code" href="classfabgl_1_1_p_s2_controller_ab8520612804a921ad834b41214a99c09.html#ab8520612804a921ad834b41214a99c09">begin</a>();</div><div class="line"></div><div class="line">  printHelp();</div><div class="line">}</div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">const</span> uint8_t SampleRates[] = { 10, 20, 40, 60, 80, 100, 200 };</div><div class="line"><span class="keywordtype">int</span> currentSampleRateIndex = 5; <span class="comment">// reset is 100 samples/sec</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">int</span> currentResolution = 2;      <span class="comment">// reset is 2 (4 counts/mm)</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">int</span> currentScaling = 1;         <span class="comment">// reset is 1 (1:1)</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="keywordtype">void</span> loop()</div><div class="line">{</div><div class="line">  <span class="keyword">auto</span> mouse = PS2Controller.<a class="code" href="classfabgl_1_1_p_s2_controller_ae2166f0cfb03c3ff63144ecd7b602bec.html#ae2166f0cfb03c3ff63144ecd7b602bec">mouse</a>();</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> (Serial.available() &gt; 0) {</div><div class="line">    <span class="keywordtype">char</span> c = Serial.read();</div><div class="line">    <span class="keywordflow">switch</span> (c) {</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;h&#39;</span>:</div><div class="line">        printHelp();</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;r&#39;</span>:</div><div class="line">        mouse-&gt;reset();</div><div class="line">        printInfo();</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;s&#39;</span>:</div><div class="line">        ++currentSampleRateIndex;</div><div class="line">        <span class="keywordflow">if</span> (currentSampleRateIndex == <span class="keyword">sizeof</span>(SampleRates))</div><div class="line">          currentSampleRateIndex = 0;</div><div class="line">        <span class="keywordflow">if</span> (mouse-&gt;setSampleRate(SampleRates[currentSampleRateIndex]))</div><div class="line">          Serial.printf(<span class="stringliteral">&quot;Sample rate = %d\n&quot;</span>, SampleRates[currentSampleRateIndex]);</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;e&#39;</span>:</div><div class="line">        ++currentResolution;</div><div class="line">        <span class="keywordflow">if</span> (currentResolution == 4)</div><div class="line">          currentResolution = 0;</div><div class="line">        <span class="keywordflow">if</span> (mouse-&gt;setResolution(currentResolution))</div><div class="line">          Serial.printf(<span class="stringliteral">&quot;Resolution = %d\n&quot;</span>, 1 &lt;&lt; currentResolution);</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">      <span class="keywordflow">case</span> <span class="charliteral">&#39;c&#39;</span>:</div><div class="line">        ++currentScaling;</div><div class="line">        <span class="keywordflow">if</span> (currentScaling == 3)</div><div class="line">          currentScaling = 1;</div><div class="line">        <span class="keywordflow">if</span> (mouse-&gt;setScaling(currentScaling))</div><div class="line">          Serial.printf(<span class="stringliteral">&quot;Scaling = 1:%d\n&quot;</span>, currentScaling);</div><div class="line">        <span class="keywordflow">break</span>;</div><div class="line">    }</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> (mouse-&gt;deltaAvailable()) {</div><div class="line">    MouseDelta mouseDelta;</div><div class="line">    mouse-&gt;getNextDelta(&amp;mouseDelta);</div><div class="line"></div><div class="line">    Serial.printf(<span class="stringliteral">&quot;deltaX = %d  deltaY = %d  deltaZ = %d  leftBtn = %d  midBtn = %d  rightBtn = %d\n&quot;</span>,</div><div class="line">                  mouseDelta.deltaX, mouseDelta.deltaY, mouseDelta.deltaZ,</div><div class="line">                  mouseDelta.buttons.left, mouseDelta.buttons.middle, mouseDelta.buttons.right);</div><div class="line">  }</div><div class="line"></div><div class="line">}</div></div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated on Mon Aug 2 2021 07:08:02 for FabGL by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.14 </li>
  </ul>
</div>
</body>
</html>
